package com.fangwei.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.fangwei.service.UserService;

@Service
public class UserServiceImpl implements UserService{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public void create(Integer id, String userName, String password) {
		this.jdbcTemplate.update("insert into tb_user(id,user_name,password) values(?,?,?)",id,userName,password);
		
	}

	@Override
	public void deleteByName(String name) {
		this.jdbcTemplate.update("delete from tb_user where user_name = ?",name);
	}

	@Override
	public Integer getAllUsers() {
		return this.jdbcTemplate.queryForObject("select count(1) from tb_user", Integer.class);
	}

	@Override
	public void deleteAllUsers() {
		this.jdbcTemplate.update("delete from tb_user");
	}

}
